#include <errno.h>
#include <signal.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <libusb.h>
#include <unistd.h>

void printbincharpad(char c);

struct libusb_device_handle *devh = NULL;

static int find_dpfp_device(void)
{
devh = libusb_open_device_with_vid_pid(NULL, 0x045e, 0x02b0);
return devh ? 0 : -EIO;
}

int main(void){
struct sigaction sigact;
int r = 1;

printf("Step 0\n");
r = libusb_init(NULL);
if (r < 0) {
fprintf(stderr, "failed to initialise libusb\n");
exit(1);
}

printf("Step 1\n");
r = find_dpfp_device();
if (r < 0) {
fprintf(stderr, "Could not find/open device\n");
exit(1);
}

printf("Step 2\n");
r = libusb_claim_interface(devh ,0);
if( r < 0){
fprintf(stderr, "usb_claim_interface error %d\n", r);
printf("Step 2 exit");
exit(0);
}

char a; 

int k;
//led blink off, 
//0x1 stops blinking
//0x4 starts blinking
//0x2 red
//0x3 yellow
//...this pattern appears to continue throughout

int code;
//k = libusb_control_transfer(devh, 0x40, 0x31, 0xfff0, 0, &a, 0, 1000);

//for(code = 0; code < 100; code ++ ){
//	printf("Trying code %d\n", code);
//	k = libusb_control_transfer(devh, 0x40, 0x06, code, 0, &a, 0, 1000);
//	sleep(2);
//	printf("k was %d\n", k);
//
//}
for(code = 65600; code > 0; code -- ) {
	printf("Trying code: %d\n", code);
	k = libusb_control_transfer(devh, 0x40, 0x31, 0, 0, &a, 0, 1000);
	sleep(4);
	:make
k = libusb_control_transfer(devh, 0x40, 0x31, 65600, 0, &a, 0, 1000);
	sleep(4);
	printf("k was %d\n", k);
}
printf("%d\n", k);
exit(1);
}

